﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Baza.EF.BLL;
using Baza.EF.DAL;



namespace Baza.EF.BLL
{
   public class DARegistration
   {
       #region Owners
       public static int RegisterOwners(Owners o, Address ad , Cities cit)
       {
           
           using(AdriaDayEntities dm = new AdriaDayEntities())
           {
           
               
               int citID = Convert.ToInt32(Connection.dm.ad_Cit_INSERT(cit.CountryID, cit.Name).FirstOrDefault());
               int adresID = 0;
               if(citID != 0)
                    adresID = Convert.ToInt32(Connection.dm.ad_Address_INSERT(citID, ad.StreetNumber, ad.Address1, ad.Address2, ad.ApartmentNumber).FirstOrDefault());
               if (adresID != 0)
                return   Convert.ToInt32(Connection.dm.ad_Owners_ISNERT(o.FirstName, o.LastName, o.Email, adresID, o.CellNumber, o.BusinessNumber, o.HomeNumber, o.FaxNumber, o.AdditionalContactInfo, o.WebsiteURL, o.PasswordSalt, o.PasswordHash,o.AboutMe,o.Photo).FirstOrDefault());
               else return 0;
           }

       }

        
       #endregion

       #region Customers
       public static int RegisterCustomers(Customers c, Address addres, Cities cities)
       {
           using (AdriaDayEntities dm = new AdriaDayEntities())
           {
               int citiID = Convert.ToInt32(Connection.dm.ad_Cit_INSERT(cities.CountryID, cities.Name).FirstOrDefault());
               int addressID = Convert.ToInt32(Connection.dm.ad_Address_INSERT(citiID, addres.StreetNumber, addres.Address1, addres.Address2, addres.ApartmentNumber).FirstOrDefault());
               
               return Convert.ToInt32(Connection.dm.ad_Customers_INSERT(c.FirstName, c.LastName, c.Email, c.PasswordSalt, c.PasswordHash,addressID,c.Phone).FirstOrDefault());
           }

       }

       #endregion

       #region Users
       public static void  RegisterUsers(Users u , Address addres , Cities cities)
       {
           int citiID = Convert.ToInt32(Connection.dm.ad_Cit_INSERT(cities.CountryID, cities.Name).FirstOrDefault());
           int addressID = Convert.ToInt32(Connection.dm.ad_Address_INSERT(citiID, addres.StreetNumber, addres.Address1, addres.Address2, addres.ApartmentNumber).FirstOrDefault());

           Connection.dm.ad_Users_INSERT(u.FirstName, u.LastName, u.Email, u.PasswordSalt, u.PasswordHash, addressID,u.Phone);
       }

       #endregion
       public static List<Countries> getAllCountres()
       {
           return Connection.dm.ad_Countries_SELECT_ALL().ToList();
       }

    }
}
